<?php
/**
 * DCRM Mobile Page
 *
 * This file is part of WEIPDCRM.
 * 
 * WEIPDCRM is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * WEIPDCRM is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 * 
 * You should have received a copy of the GNU Affero General Public License
 * along with WEIPDCRM.  If not, see <http://www.gnu.org/licenses/>.
 */

require_once('system/common.inc.php');

base_url();

// URL For Rewrite 
$rewrite_mod = get_option('rewrite_mod');
switch($rewrite_mod){
	case 3:
		$rewrite_url = array('public' => 'public-%d.html','search' => 'search-mfss.html','public_nohistory' => 'public/%d/nohistory', 'screenshot' => 'screenshot/%d', 'history' => 'history/%d', 'contact' => 'contact/%d', 'pcsection' => 'list-%d.html','mipublic' => 'list-pg-%d.html','mipcpage' => 'list-%1$d-pg-%2$d.html', 'report' => 'report/%d', 'report_support' => 'report/%1$d/%2$d', 'more' => 'more/%d', 'more_offset' => 'more/%1$d/%2$d', 'misc' => 'misc','down' => 'downloads.html');
		break;
	case 1:
	case 2:
	default:
		$rewrite_url = array('view' => 'index.php?method=view&amp;pid=%d', 'view_nohistory' => 'index.php?pid=%d&amp;addr=nohistory', 'screenshot' => 'index.php?method=screenshot&amp;pid=%d', 'history' => 'index.php?method=history&amp;pid=%d', 'contact' => 'index.php?method=contact&amp;pid=%d', 'section' => 'index.php?method=section&amp;pid=%d', 'report' => 'index.php?method=report&amp;pid=%d', 'report_support' => 'index.php?method=report&amp;pid=%1$d&amp;support=%2$d', 'more' => 'index.php?method=more&amp;pid=%d', 'more_offset' => 'index.php?method=more&amp;pid=%1$d&amp;offset=%2$d', 'misc' => 'misc.php');
		break;
}
function echo_rewrite_url($type, $variable1, $variable2=''){
	global $rewrite_url;
	echo SITE_URL;
	printf($rewrite_url[$type], $variable1, $variable2);
}

class_loader('Mobile_Detect');
$detect = new Mobile_Detect;
if(!$detect->isiOS()){
	if (DCRM_PCINDEX == 1) {
		header("Location: ".SITE_URL."favourite.php");
		exit();
	} else {
		$isCydia = false;
	}
} else {
	if (DCRM_MOBILE == 2) {
		if (!strpos($detect->getUserAgent(), 'Cydia')) {
			$isCydia = false;
		} else {
			$isCydia = true;
		}
	} else {
		exit('Access Denied');
	}
}
if (file_exists('Release')) {
	$release = file('Release');
	$release_origin = __('No Name');
	$release_mtime = filemtime('Release');
	$release_time = date('Y-m-d H:i:s',$release_mtime);
	foreach ($release as $line) {
		if(preg_match('#^Origin#', $line)) {
			$release_origin = trim(preg_replace("#^(.+):\\s*(.+)#","$2", $line));
		}
		if(preg_match("#^Description#", $line)) {
			$release_description = trim(preg_replace("#^(.+):\\s*(.+)#","$2", $line));
		}
	}
} else {
	$release_origin = __('Empty Page');
}
if (isset($_GET['pid'])) {
	if (ctype_digit($_GET['pid']) && intval($_GET['pid']) <= 10000) {
		function device_check(){
			global $detect;
			$device_type = array('iPhone', 'iPod', 'iPad');
			for ($i = 0; $i < count($device_type); $i++) {
				$check = $detect->version($device_type[$i]);
				if ($check !== false) {
					if (isset($_SERVER['HTTP_X_MACHINE'])) {
						$DEVICE = $_SERVER['HTTP_X_MACHINE'];
					} else {
						$DEVICE = 'Unknown';
					}
					$OS = str_replace('_', '.', $check);
					break;
				}
			}
			return array('DEVICE' => $DEVICE, 'OS' => $OS);
		}

		if (isset($_GET['method']) && $_GET['method'] == 'screenshot') {
			$index = 2;
			$title = __('View Screenshots');
		} elseif (isset($_GET['method']) && $_GET['method'] == 'report') {
			$device_info = device_check();
			if (!isset($_GET['support'])) {
				$index = 3;
			} else {
				if ($_GET['support'] == '1') {
					$support = 1;
				} elseif ($_GET['support'] == '2') {
					$support = 2;
				} elseif ($_GET['support'] == '3') {
					$support = 3;
				} else {
					$support = 0;
				}
				$index = 4;
			}
			$title = __('Report Problems');
		} elseif (isset($_GET['method']) && $_GET['method'] == 'history') {
			$index = 5;
			$title = __('Version History');
		} elseif (isset($_GET['method']) && $_GET['method'] == 'contact') {
			$index = 6;
			$title = __('Contact us');
		} elseif (isset($_GET['method']) && $_GET['method'] == 'pcsection') {
			$index = 7;
          $section = DB::fetch_first("SELECT `Name`, `Icon` FROM `".DCRM_CON_PREFIX."Sections` WHERE `ID` = '".(int)$_GET['pid']."'");
			$title = __(DB::real_escape_string($section['Name']));
		} elseif (isset($_GET['method']) && $_GET['method'] == 'more') {
			$index = 8;
			$section = DB::fetch_first("SELECT `Name`, `Icon` FROM `".DCRM_CON_PREFIX."Sections` WHERE `ID` = '".(int)$_GET['pid']."'");
			$q_name = DB::real_escape_string($section['Name']);
			if (isset($_GET['offset']) && !empty($_GET['offset']) && ctype_digit($_GET['offset'])) {
				$offset = intval($_GET['offset']);
			} else {
				$offset = 0;
			}
			$packages = DB::fetch_all("SELECT `ID`, `Name`, `Package` FROM `".DCRM_CON_PREFIX."Packages` WHERE (`Stat` = '1' AND `Section` = '".$q_name."') ORDER BY `ID` DESC LIMIT 10 OFFSET ".$offset);
			foreach($packages as $package){
				if(!empty($package)){
					if ($isCydia) { ?>
				<a href="cydia://package/<?php echo($package['Package']); ?>" target="_blank">
<?php					} else { ?>
				<li>
	<a href="<?php echo_rewrite_url('pc', $package['ID']);?>" class="app_icon" >
<?php					} ?>
	
    
<div class="desc" ><?php echo ($package['Description']);  ?></div>
</li>
<?php
				}
			}
			exit();
		} elseif (!isset($_GET['method']) || (isset($_GET['method']) && $_GET['method'] == 'public')) {
			$index = 1;
			$title = __('View Package');
			$package_id = (int)DB::real_escape_string($_GET['pid']);
			$package_info = DB::fetch_first("SELECT `Name`, `Version`, `Author`, `Package`, `Description`, `DownloadTimes`, `Multi`, `CreateStamp`, `Size`, `Installed-Size`, `Section`, `Homepage`, `Tag`, `Level`, `Price`, `Purchase_Link`, `Changelog`, `Changelog_Older_Shows`, `Video_Preview`, `System_Support`, `ScreenShots` FROM `".DCRM_CON_PREFIX."Packages` WHERE `ID` = '".$package_id."' LIMIT 1");
			if ($package_info) $title = $package_info['Name'];
		} else {
			httpinfo(405);
			exit();
		}
	} else {
		httpinfo(405);
		exit();
	}
} elseif (!isset($_GET['method'])) {
	$index = 0;
	$title = $release_origin;
} else {
	httpinfo(405);
	exit();
}
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<title><?php echo($title); ?> | 最简洁的中文源</title>
		<meta charset="utf-8">
		<meta name="robots" content="index, follow" />
      <mobile:mobile type="pc,mobile"/>
      <meta name="description" content="<?php echo(AUTOFILL_KEYWORDS); ?>" />
<?php
if (defined("AUTOFILL_SEO")) {
?>
		<meta name="title" content="<?php echo(AUTOFILL_SEO); ?>" />
<?php
}
if (!empty($release_description)) {
?>
		<meta name="description" content="<?php echo($release_description); ?>" />
<?php
}
if (defined("AUTOFILL_KEYWORDS")) {
?>
		<meta name ="keywords" content="<?php echo(AUTOFILL_KEYWORDS); ?>" />
<?php
}
if ($isCydia) {
?>
		<base target="_blank">
<?php
} else {
?>
		<base target="_top">
<?php
}
?>
<link rel="apple-touch-icon" href="<?php echo(SITE_URL); ?>CydiaIcon.png">
<link rel="shortcut icon" href="<?php echo(SITE_URL); ?>favicon.ico">
<link rel="stylesheet" type="text/css" href="<?php echo(SITE_URL); ?>ziyuan/css/base.css" />
<link rel="stylesheet" type="text/css" href="<?php echo(SITE_URL); ?>ziyuan/css/list.css" />
<link rel="stylesheet" type="text/css" href="<?php echo(SITE_URL); ?>ziyuan/css/rank.css" />
<link rel="stylesheet" href="<?php echo(SITE_URL); ?>ziyuan/css/youtiy.css" media="all">
<script type="text/javascript" src="<?php echo(SITE_URL); ?>ziyuan/js/udidtj.js" ></script>
      
      

	</head>
	<body class="pinstripe">
		<panel>
<?php
$repo_url = base64_decode(DCRM_REPOURL);
if ($index == 0) {
	if (!$isCydia) {
?>
			 <!-- Global Topbar -->
    <div class="global_topbar_wrap">
		<div id="global_topbar" class="global_topbar">
			<div class="wrap inner">
                    
<?php                                                                 
    if (defined("AUTOFILL_PCDBZDYMC1") or defined("AUTOFILL_PCDBZDY1") or defined("AUTOFILL_ZTMHDZ1") or defined("AUTOFILL_ZTMHDZMC1") or defined("AUTOFILL_YYWXZQ1") or defined("AUTOFILL_YYWXZQMC1") or defined("AUTOFILL_YYZJBB1") or defined("AUTOFILL_YYZJBBMC1") or defined("AUTOFILL_WLPJHZ1") or defined("AUTOFILL_WLPJHZMC1")) {
?>              
				<div class="services" id="global_topbar_services">
					<ul>
<?php
                                                                   
    if (defined("AUTOFILL_PCDBZDY1") && defined("AUTOFILL_PCDBZDYMC1")) {
?>                        
                    <li class="current"><a href="<?php echo(AUTOFILL_PCDBZDY1); ?>"><i class="weiphone"></i><?php echo(AUTOFILL_PCDBZDYMC1); ?></a></li>
<?php
    }                                                                     
    if (defined("AUTOFILL_ZTMHDZ1") && defined("AUTOFILL_ZTMHDZMC1")) {
?>                       
						<li><a href="<?php echo(AUTOFILL_ZTMHDZ1); ?>" target="_blank"><i class="wegame"></i><?php echo(AUTOFILL_ZTMHDZMC1); ?></a></li>
<?php
    }                                                                     
    if (defined("AUTOFILL_YYZJBB1") && defined("AUTOFILL_YYZJBBMC1")) {
?>                       
						<li><a href="<?php echo(AUTOFILL_YYZJBB1); ?>" target="_blank"><i class="fengbuy"></i><?php echo(AUTOFILL_YYZJBBMC1); ?></a></li>
<?php
    }                                                                     
    if (defined("AUTOFILL_WLPJHZ1") && defined("AUTOFILL_WLPJHZMC1")) {
?>                       
						<li><a href="<?php echo(AUTOFILL_WLPJHZ1); ?>" target="_blank"><i class="wper"></i><?php echo(AUTOFILL_WLPJHZMC1); ?></a></li>
<?php
    }                                                                     
    if (defined("AUTOFILL_YYWXZQ1") && defined("AUTOFILL_YYWXZQMC1")) {
?>                       
						<li><a href="<?php echo(AUTOFILL_YYWXZQ1); ?>" ><i class="weand"></i><?php echo(AUTOFILL_YYWXZQMC1); ?></a></li>
                     
<?php
	}
?>						
                     
					</ul>
					<a href="javascript:;" class="expand"><span>展开</span></a>
				</div>               
<?php
	}
?>	              
				<div class="links" id="globar_topbar_links">
					<ul>
						<li><a href="<?php echo(SITE_URL); ?>" target="_blank">首页</a></li>
<?php
	if (defined("AUTOFILL_PCDBZDY") && defined("AUTOFILL_PCDBZDY_NAME")) {
?>              
			<li><a href="<?php echo(AUTOFILL_PCDBZDY); ?>" target="_blank"><?php echo(AUTOFILL_PCDBZDY_NAME); ?></a></li> 
<?php
	}
?> 
					</ul>
					<div class="focus"><em></em></div>
				</div>
                <div class="user_menu">
				<ul>
<?php
require_once 'qqlogin/function.php';
require_once 'qqlogin/Connect2.1/qqConnectAPI.php';	
?>                  
<?php if(!isset($_SESSION["accesstoken"]) || !isset($_SESSION["openid"])) { ?>
		<li><a href="/qqlogin/qqlogin.php">登录</a></li>        
<?php } else { 
    $qc = new QC($_SESSION["accesstoken"],$_SESSION["openid"]);
    $arr = $qc->get_user_info();           
?>  
                <li><img class="icon" src="<?php echo $arr['figureurl_qq_2'];?>" style="border-radius: 50%; width: 20px; height: 20px; box-shadow:0 0 1px #AAA;padding:1px;margin-right: 1px;"></li>   
                <li>用户名：<?php echo $arr['nickname'];?></li>  
				<li><a href="User.php" target="_blank">个人中心</a></li>
                <li><a onclick="cookipost()" >退出登录</a></li>  
 <script language="javascript">
    function cookipost(){
      $.get("/qqlogin/qqlogout.php", function(result){
        alert('账户退出');
    	window.location.href='<?php echo(SITE_URL); ?>';
  	  });  
	}
</script>                  
<?php
}
?> 
                  
      
 <?php 
if(isset($_SESSION["accesstoken"]) || isset($_SESSION["openid"])) {      
$User=$arr["nickname"];
$Logo=$arr['figureurl_qq_2'];
$Openid=$_SESSION["openid"];
$date=date("Y-m-d h:i:s");
$ip = ($ip) ? $ip : $_SERVER["REMOTE_ADDR"];   
if($row=DB::result_first("SELECT * FROM `".DCRM_CON_PREFIX."User` WHERE `Openid`='".$Openid."'" )){    
  $sql = DB::query("UPDATE `".DCRM_CON_PREFIX."User` SET `Logo` = '".$Logo."', `User` = '".$User."',`IP` = '".$ip."' WHERE `Openid`='".$Openid."'");
} else {  
  $query = DB::query("INSERT INTO `".DCRM_CON_PREFIX."User` (ID,User,Logo,Openid,Packages,Collection,TimeStamp,IP) VALUES ('','$User','$Logo','$Openid','','','$date','$ip')");
}      
}
?> 
                 
				</ul>
			    </div>
			</div>
		</div>
	</div> 
          
<!-- Header -->
<div class="header_wrap">
	<div id="header" class="header">
		<div class="wrap_con header_inner">
			<h2><a href="<?php echo(SITE_URL); ?>"><?php echo(AUTOFILL_SEO); ?></a></h2>
			<div class="navigator">
				<ul>
					<li >
						<a href="<?php echo(SITE_URL); ?>">
							<i class="home"></i><span>首页</span>
						</a>
					</li>
					<li >
						<a href="<?php echo(SITE_URL); ?>public.html">
							<i class="list"></i><span>资源列表</span>
						</a>
					</li>
<?php
	if (defined("AUTOFILL_PCZDYDH") && defined("AUTOFILL_PCZDYDH_NAME")) {
?>                   
					<li >
						<a href="<?php echo(AUTOFILL_PCZDYDH); ?>">
							<i class="rank"></i><span><?php echo(AUTOFILL_PCZDYDH_NAME); ?></span>
						</a>
					</li>
<?php
    }                                                                     
    if (defined("AUTOFILL_PCZDYDH2") && defined("AUTOFILL_PCZDYDH2_NAME")) {
?>                   
					<li >
					     <a href="<?php echo(AUTOFILL_PCZDYDH2); ?>" >
						<i class="me"></i><span><?php echo(AUTOFILL_PCZDYDH2_NAME); ?></span>
                         </a>
					</li>
                           
<?php
    }                                                                     
?>   
				</ul>
			</div>
		</div>
	</div>
</div>           
<!-- 变化开始 -->
<!-- main4 -->
<!--资源列表-->

<?php
	}
?>
<?php if(!isset($_SESSION["accesstoken"]) || !isset($_SESSION["openid"])) { ?>
		<meta http-equiv="refresh" content="0;url=<?php echo(SITE_URL); ?>qqlogin/qqlogin.php">        
<?php } ?>  

    
<div class="personal_source clearfix">
	<div class="wrap_con">
		<div class="header_pic">
			<img src="<?php echo $arr['figureurl_qq_2'];?>" height="118" width="118">
			<i class="mask"></i>
		</div>
		<div class="personal_abs">
			<div class="name_web_link">
				<span class="name">
				<a href="<?php echo(SITE_URL); ?>"><?php echo $arr['nickname'];?></a>
<?php
 if($row=DB::result_first("SELECT `ID`,`UDID`,`OPENID`,`Level`,`Packages`,`Comment` FROM `apt_UDID` WHERE `Openid`='".$_SESSION['openid']."'" )){      
 
 } else {
?> 
                  
              <span class="certification" title="<?php echo(AUTOFILL_SEO); ?>组织认证"></span>    
<?php
 }
       $ress = DB::query("SELECT * FROM `apt_UDID` WHERE `Openid`='".$_SESSION['openid']."' and `Level` ='0'");
		foreach($ress as $res){ 
?>                  
                  <span class="certification" title="<?php echo(AUTOFILL_SEO); ?>组织认证"></span>
<?php  
 }
         $ress = DB::query("SELECT * FROM `apt_UDID` WHERE `Openid`='".$_SESSION['openid']."'and `Level` ='1'");
		foreach($ress as $res){ 
?>                   
                  <span class="medial_personal" title="<?php echo(AUTOFILL_SEO); ?>组织认证"></span>
<?php  
 }
         $ress = DB::query("SELECT * FROM `apt_UDID` WHERE `Openid`='".$_SESSION['openid']."'and `Level` ='2'");
		foreach($ress as $res){ 
?>                   
                  <span class="medial_personal" title="<?php echo(AUTOFILL_SEO); ?>组织认证"></span>   
<?php  
 }
         $ress = DB::query("SELECT * FROM `apt_UDID` WHERE `Openid`='".$_SESSION['openid']."'and `Level` ='3'");
		foreach($ress as $res){ 
?>                   
                  <span class="medial_personal" title="<?php echo(AUTOFILL_SEO); ?>组织认证"></span>                    
<?php
}                              
       $ress = DB::query("SELECT * FROM `apt_UDID` WHERE `Openid`='".$_SESSION['openid']."'and `Level` ='4'");
		foreach($ress as $res){ 
?>                  
                  <span class="medial"  title="<?php echo(AUTOFILL_SEO); ?>组织认证"></span>
<?php  
 }
?>                  
            <span target="_blank" class="web_address"><br>用户ID：<?php echo $_SESSION["openid"];?></span>
			</span></div>
			<p class="others_info">
				我的源我做主，收集我最喜爱的资源，这就是<?php echo(AUTOFILL_SEO); ?>
			</p>
		</div>
    
<?php
$num = DB::result_first("SELECT count(*) FROM `".DCRM_CON_PREFIX."Collection` WHERE `UserOpenID`='".$_SESSION['openid']."'");
$num2 = DB::result_first("SELECT count(*) FROM `".DCRM_CON_PREFIX."DebUpdate` WHERE `OPENID`='".$_SESSION['openid']."'");
?>
        
		<div class="popular">
			<div class="top_cit">
<?php
   if($row=DB::result_first("SELECT * FROM `".DCRM_CON_PREFIX."User` WHERE `OPENID`='".$_SESSION['openid']."' and `Packages`= '1'")){      
?> 
             <em>收藏数量：</em><span><?php echo $num ?>个</span><em>&nbsp;&nbsp;上传数量：</em><span><?php echo $num2 ?>个</span> 
<?php
 } else {
?> 			
              
              <em>收藏数量：</em><span><?php echo $num ?>个</span>
 <?php
 }
?> 
			</div>
			<div class="bottom_cit">      

             			

<?php
   if($row=DB::result_first("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`LevelLogo`,`LevelName`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `OPENID`='".$_SESSION['openid']."'" )){      
?>
<?php
          $ress = DB::query("SELECT `Level` FROM `".DCRM_CON_PREFIX."Activation` WHERE `Openid`='".$_SESSION['openid']."'");
		foreach($ress as $res){       
?>        

                    <em>用户等级：</em><span>
                    <?php 
                    if($res['Level']=='2'){ echo '蓝苹果会员';}
                    if($res['Level']=='3'){echo '铜苹果会员';}  
                    if($res['Level']=='4'){echo '银苹果会员';}       
                    if($res['Level']=='5'){echo '金苹果会员';}      
                    if($res['Level']=='6'){echo '白金尊贵会员';}       
                    if($res['Level']=='7'){echo '系统管理员';}     
                    ?></span>	

<?php
 }
 } else {
?>            
					<em>用户等级：</em><span>小苹果会员</span><br>
<?php  
 } 
?> 
            
              <!--span>☆</span> <em>用户等级</em-->
 <script> 
jQuery(document).ready(function($) {
	$('.theme-login').click(function(){
		$('.theme-popover-mask').fadeIn(100);
		$('.theme-popover').slideDown(200);
	})
	$('.theme-poptit .close').click(function(){
		$('.theme-popover-mask').fadeOut(100);
		$('.theme-popover').slideUp(200);
	})
 
})
</script>               
			</div>
		</div>
        <div class="data_set_btn">
<a class="btn btn-primary btn-large theme-login" href="javascript:;">会员组升级</a>
      </div>
		</div>
      </div>
<div class="theme-popover">
     <div class="theme-poptit">
	      会员组升级
          <a href="javascript:;" title="关闭" class="close">×</a>
     </div>
     <div class="theme-popbod dform">
           <form class="theme-signin" name="loginform" action="" method="get">
                <ol>
                     <li><strong>UDID：</strong><input class="ipt" type="text" name="UDID" value="" size="20" /></li>
                     <li><strong>激活码：</strong><input class="ipt" type="text" name="Activation" value="" size="20" /></li>					 
                     <li><button class="btn2 btn-primary" type="submit"  >激活用户组</button></li>
                </ol>
           </form>
     </div>
</div>    
<div class="theme-popover-mask"></div>
          
<div class="origin_tab clearfix">
	<div class="wrap_con">
		<div class="origin_con">

<div class="origin_nav">
	<ul>
		<li><a href="User.php" ><i class="my_resources"></i><span>我的资源</span></a></li>
		<li><a href="ReSource.php" class="current"  ><i class="my_upload"></i><span>我的上传</span></a></li>
		<li><a  href="Worklist.php" ><i class="my_album"></i><span>我的反馈</span></a></li>
			</ul>
</div>
          

<?php 

if(isset($_GET['UDID'])){ 
if($_GET['UDID']==null or $_GET['Activation']==null){
  echo "<script> alert('UDID不能为空');parent.location.href='User.php'; </script>"; 
}else{    
$OPENID=$_SESSION['openid'];  
$udid=$_GET["UDID"];
$Activation=$_GET['Activation'];  
$date=date("Y-m-d h:i:s"); 
$ress = DB::query("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `KM`='".$_GET['Activation']."'");
foreach($ress as $res){  
$level=$res['Level'];   
if($row=DB::result_first("SELECT `ID`,`KM`,`UDID`,`OPENID`,`Level`,`Activation`,`TimeStamp`,`CreateStamp` FROM `".DCRM_CON_PREFIX."Activation` WHERE `KM`='".$Activation."'and `Activation`='未使用'" )){  
  $sql = DB::query("UPDATE `".DCRM_CON_PREFIX."Activation` SET `UDID` = '".$udid."', `OPENID` = '".$OPENID."', `Activation` = '已使用', `CreateStamp` = '".$date."' WHERE `KM`='".$Activation."'and `Activation`='未使用'"); //第一步写入用户数据到激活码表
if($row=DB::result_first("SELECT `UDID` FROM `".DCRM_CON_PREFIX."UDID` WHERE `UDID`='".$udid."'" )){    
  $sql = DB::query("UPDATE `".DCRM_CON_PREFIX."UDID` SET `UDID` = '".$udid."', `OPENID` = '".$OPENID."',`TimeStamp` = '".$date."',`Level` = '".$level."',`CreateStamp` = '".$date."' WHERE `UDID`='".$udid."'");
   echo "<script> alert('激活成功');parent.location.href='User.php'; </script>"; 
} else {  
  $query = DB::query("INSERT INTO `".DCRM_CON_PREFIX."UDID` (ID,UDID,OPENID,Level,Packages,Comment,TimeStamp,Downloads,IP,CreateStamp) VALUES ('','$udid','$OPENID','$level','','','$date','','$ip','$date')");
  echo "<script> alert('激活成功');parent.location.href='User.php'; </script>"; 
}     
} else {
 echo "<script>alert('激活失败');parent.location.href='User.php';</script>";   
}
}
}
}

?>   
         
			<!--right-->
			<div class="main_module clearfix" id="mainlist_div">
				<h2 class="title">请填写上传软件信息<em id="all_group_resouce_count"></em></h2>
				<!--编辑模块-->
				<div class="edit_module clearfix">            
				<form name="form" method="post" enctype="multipart/form-data">
				<input id="id" name="id" type="hidden" value="579dfe32fab7c29c258b45f0">
				<div class="form_content clearfix" style="">
					<ul style="">
						<li>
							<label>软件名称：</label>
							<input type="text" placeholder="请输入软件版本" name="Name" class="input" value="">
                            <span class=" note"><em>*</em><i>（软件名称,将用于Web和Cydia的显示）</i></span>
						</li>
						<li>
							<label>软件作者：</label>
							<input type="text" placeholder="请输入软件名称" name="Author" class="input" value="">
                            <span class=" note"><em>*</em><i>（请如实填写插件作者）</i></span>
						</li>
						<li>
							<label>软件分类：</label>
							<select class="input" name="Depiction" >                            
							<option value="未选择" selected="">选择分类</option>  
							<?php
							$sections = DB::fetch_all("SELECT `ID`, `Name`, `Icon` FROM `".DCRM_CON_PREFIX."Sections`");
							foreach($sections as $section){
							?> 
							<option value="<?php echo($section['Name']); ?>"><?php echo($section['Name']); ?></option>
							<?php
							}
							?>
							</select>
                          <span class=" note"><em>*</em><i>（请选择软件分类）</i></span>
						</li>
						<li>
							<label>系统要求：</label>
							<select class="input" name="System" >
                            <option value="IOS全系统" selected="">IOS全系统</option>
                            <option value="IOS9.0-9.3.3">IOS9.0-9.3.3</option>
                            <option value="IOS9.2-9.3.3">IOS9.2-9.3.3</option>
                            <option value="IOS9.0-10.2">IOS9.0-10.2</option>
                            <option value="IOS9.2-10.2">IOS9.2-10.2</option>
                            <option value="IOS9.0-10.3.3">IOS9.0-10.3.3</option>
                            <option value="IOS9.2-10.3.3">IOS9.2-10.3.3</option>
                            <option value="IOS9.0-11.1.2">IOS9.0-11.1.2</option>
                            <option value="IOS9.2-11.1.2">IOS9.2-11.1.2</option>
                            <option value="IOS9.0-11.4">IOS9.0-11.4</option>
                            <option value="IOS9.2-11.4">IOS9.0-11.4</option>
							<option value="IOS10-11.1.2">IOS10-11.1.2</option>
							<option value="IOS10.2-11.1.2">IOS10.2-11.1.2</option>
							<option value="IOS10-11.4">IOS10-11.4</option>
							<option value="IOS10.2-11.4">IOS9.0-11.4</option>
							<option value="IOS11.1.2-11.4">IOS10-11.4</option>
							<option value="IOS11.2-11.4">IOS11.0-11.3.1</option>
							<option value="IOS11.2-11.4">IOS11.0-11.4</option></select>
                          <span class=" note"><em>*</em><i>（请选择系统要求）</i></span>
						</li>
						<li>
							<label>常用邮箱：</label>
                            <input type="text" placeholder="请输入软件功能及描述" name="Mail" class="input" value="">
							<span class=" note"><em>*</em><i>（请输入您的邮箱，方便与您联系。）</i></span>
						</li>
						<li>
							<label>插件是否付费：</label>
							<select name="Level" class="field--input">
							<option value="是" selected="">是</option>
                            <option value="否">否</option></select>
							<span class=" note"><em>*</em><i>（插件是否需要用户付费下载）</i></span>
						</li>	
                  
                        <li>
							<label>投递过其他源：</label>
							<select class="field--input" name="Price" >
							<option value="是" >是</option>
							<option value="否" selected="">否</option></select>
							<span class=" note"><em>*</em><i>（其他私人软件源是否拥有该插件）</i></span>
						</li>
                  		<li>
							<label>软件描述：</label>
							<textarea class="textarea"  name="Description"></textarea>
							<span class=" note"><em>*</em><i>（描述只显示在iPhone/iPad/Cydia源的软件简介里.）</i></span>
						</li>
						<li>
						<label>DEB上传：</label>
						<span class="up_file">
                              <input type="file" name="file" id="file" >
                              <input type="hidden" name="sf" value="sf"/>
						</span>
							<div class="note"><em>*</em>仅支持deb文件</div>
						</li>
					
						<li><input class="confirm_btn" type="submit" name="sub" value="提交"></li>
					</ul>
			</div>
			</form> 

               </div>
            </div>

<?php
function kmtype(){ 
  $appid=AUTOFILL_WXAPPID;
  $secret=AUTOFILL_WXKEYID;
  $template_id=AUTOFILL_CJOPENID;
  $openid=AUTOFILL_WXOPENID;
$ac = file_get_contents('https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid='.$appid.'&secret='.$secret);
$wxt = json_decode($ac,true);
$url = 'https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=' . $wxt['access_token'];//access_token改成你的有效值
$time=date('Y-m-d h:i:s'); 
$ress = DB::query("SELECT * FROM `".DCRM_CON_PREFIX."User` WHERE `Openid`='".$_SESSION['openid']."'");
foreach($ress as $res){       
$nameuser=$res['User'];  
$openidqx=$res['Openid'];  
$scName=$_POST['Name'];  
$data = array(
    'first' => array(
        'value' => '插件上传审核申请！',
        'color' => '#FF0000'
    ),
    'keyword1' => array(
        'value' => $time,
        'color' => '#FF0000'
    ),
    'keyword2' => array(
        'value' => '用户'.$nameuser.'上传软件名称：'.$scName.'待审核',
        'color' => '#FF0000'
    ),
    'remark' => array(
        'value' => '请前往审核！！',
        'color' => '#FF0000'
    )
);
$template_msg=array('touser'=>$openid,'template_id'=>$template_id,'topcolor'=>'#FF0000','data'=>$data); 
$curl = curl_init($url);
$header = array();
$header[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
// 不输出header头信息
curl_setopt($curl, CURLOPT_HEADER, 0);
// 伪装浏览器
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36');
// 保存到字符串而不是输出
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// post数据
curl_setopt($curl, CURLOPT_POST, 1);
// 请求数据
curl_setopt($curl,CURLOPT_POSTFIELDS,json_encode($template_msg));
$response = curl_exec($curl);
curl_close($curl);  
 //echo $response;      
} 
}
?>          
<?php 
if($row=DB::result_first("SELECT * FROM `".DCRM_CON_PREFIX."User` WHERE `Openid`='".$_SESSION["openid"]."' and `Packages` != '1'" )){  
   echo "<script>alert('上传失败！原因您没有上传权限！请联系管理员开通');parent.location.href='User.php';</script>";  
}else{  
if(isset($_POST['Author'])||isset($_POST['Name'])){ 
if($_POST['Author']==null or $_POST['Name']==null){
  echo "<script> alert('提交失败，请检查提交内容是否有空值');parent.location.href='DebUp.php'; </script>"; 
}else{   
$open=$_SESSION["openid"];  
$UserName=$arr['nickname'];  
$Name=$_POST['Name'];
$Author=$_POST['Author'];
$Mail=$_POST['Mail'];
$Level=$_POST['Level'];
$Price=$_POST['Price'];
$Description=$_POST['Description'];
$Depiction=$_POST['Depiction'];  
$System=$_POST['System'];
$ip = ($ip) ? $ip : $_SERVER["REMOTE_ADDR"];    
$date=date("Y-m-d h:i:s");   
 
$query = DB::query("INSERT INTO `".DCRM_CON_PREFIX."DebUpdate` (ID,UserName,OPENID,Name,Author,Mail,Level,Price,Description,Depiction,System,Examine,TimeStamp) VALUES ('','$UserName','$open','$Name','$Author','$Mail','$Level','$Price','$Description','$Depiction','$System','未审核','$date')");
$sql = DB::query("UPDATE `".DCRM_CON_PREFIX."User` SET `Collection` = (Collection)+1 WHERE `Openid`='".$_SESSION['openid']."' and `Packages`='1'");
$wxtz =kmtype();
 
}
} 
}
 
  ?>
<?php  
  /**
   * 文件上传
   * email :478066693@qq.com
   * time :2018/7/26
   */
  
  class UploadFile{
    private $max_size   = '2000000000000000000000000000000000000000000000000000000000'; //设置上传文件的大小，此为2M
    private $rand_name   = false;   //是否采用随机命名
    private $allow_type  = array();  //允许上传的文件扩展名
    private $error     = 0;     //错误代号
    private $msg      = '';    //信息
    private $new_name   = '';    //上传后的文件名
    private $save_path   = '';    //文件保存路径
    private $uploaded   = '';    //路径.文件名
    private $file     = '';    //等待上传的文件
    private $file_type   = array();  //文件类型
    private $file_ext   = '';    //上传文件的扩展名
    private $file_name   = '';    //文件原名称
    private $file_size   = 0;     //文件大小
    private $file_tmp_name = '';    //文件临时名称

    /**
     * 构造函数，初始化
     * @param string $rand_name 是否随机命名
     * @param string $save_path 文件保存路径
     * @param string $allow_type 允许上传类型
        $allow_type可为数组  array('jpg', 'jpeg', 'png', 'gif');
        $allow_type可为字符串 'jpg|jpeg|png|gif';中间可用' ', ',', ';', '|'分割
     */
    public function __construct($rand_name=true, $save_path='./upload/', $allow_type=''){
      $this->rand_name = $rand_name;
      $this->save_path = $save_path;
      $this->allow_type = $this->get_allow_type($allow_type);
    }
     
    /**
     * 上传文件
     * 在上传文件前要做的工作
     * (1) 获取文件所有信息
     * (2) 判断上传文件是否合法
     * (3) 设置文件存放路径
     * (4) 是否重命名
     * (5) 上传完成
     * @param array $file 上传文件
     *     $file须包含$file['name'], $file['size'], $file['error'], $file['tmp_name']
     */
    public function upload_file($file){
      //$this->file   = $file;
      $this->file_name   = $file['name'];
      $this->file_size   = $file['size'];
      $this->error     = $file['error'];
      $this->file_tmp_name = $file['tmp_name'];
       
      $this->ext = $this->get_file_type($this->file_name);
       
      switch($this->error){
        case 0: $this->msg = ''; break;
        case 1: $this->msg = '超出了php.ini中文件大小'; break;
        case 2: $this->msg = '超出了MAX_FILE_SIZE的文件大小'; break;
        case 3: $this->msg = '文件被部分上传'; break;
        case 4: $this->msg = '没有文件上传'; break;
        case 5: $this->msg = '文件大小为0'; break;
        default: $this->msg = '上传失败'; break;
      }
      if($this->error==0 && is_uploaded_file($this->file_tmp_name)){
        //检测文件类型
        if(in_array($this->ext, $this->allow_type)==false){
          $this->msg = "<script>alert('软件包上传失败原因:文件类型不正确，请上传deb格式文件')</script>";
          return false;
        }
        //检测文件大小
        if($this->file_size > $this->max_size){
          $this->msg = "<script>alert('软件包上传失败原因:上传文件大小超过限制！<br>请联系管理员')</script>";
          return false;
        }
      }
      $this->set_file_name();
      $this->uploaded = $this->save_path.$this->new_name;
      if(move_uploaded_file($this->file_tmp_name, $this->uploaded)){
       
        
        $this->msg = "<script> alert('软件包上传成功感谢您的提交');parent.location.href='DebUp.php';</script>";   
        
        return true;
        
      }else{
        $this->msg = "<script>alert('软件包上传失败')</script>";
        
        return false;
      }
    }

    /**
    * 设置上传后的文件名
    * 当前的毫秒数和原扩展名为新文件名
    */
    
    
    
    
    
    public function set_file_name(){
      if($this->rand_name==true){
        $a = explode(' ', microtime());
        $t = $a[1].($a[0]*1000000);
        $this->new_name = $_POST['Name'].'.'.($this->ext);//重名名后写入数据库 
      }else{
        $this->new_name = $this->file_name;
      }
    }
   
    /**
    * 获取上传文件类型
    * @param string $filename 目标文件
    * @return string $ext 文件类型
    */
    public function get_file_type($filename){
      $ext = pathinfo($filename, PATHINFO_EXTENSION);
      return $ext;
    }
     
    /**
     * 获取可上传文件的类型
     */
    public function get_allow_type($allow_type){
      $s = array();
      if(is_array($allow_type)){
        foreach($allow_type as $value){
          $s[] = $value;
        }
      }else{
        $s = preg_split("/[\s,|;]+/", $allow_type);
      }
      return $s;
    }
     
    //获取错误信息
    public function get_msg(){
      return $this->msg;
    }
  }
                  
                  
?>
  <?php
    if(isset($_POST['sf']) && $_POST['sf']=='sf'){
      if ($_FILES["file"]["error"] > 0){
        echo "Error: " . $_FILES["file"]["error"] . "<br />";
      }else{
        $file = $_FILES['file'];
        $upload = new UploadFile(true, './upload/', array('deb'));
        $upload->upload_file($file);
        echo $upload->get_msg();
      }
    }else{
  ?>   
<?php
    }
?>
          
          
          
<?php
	}
?>
	     </div>
      </div>
   </div>  
<br> <br> <br> <br> <br> <br> <br> <br> <br> <br>  <br> <br> <br> <br> <br> <br> <br> <br> <br> <br>  <br> <br> <br> <br> 
<!-- footer -->
<!--随便看看-->
<?php     
    if (defined("AUTOFILL_QXWZMC1") or defined("AUTOFILL_QXWZDZ1") or defined("AUTOFILL_QXWZMC2") or defined("AUTOFILL_QXWZDZ2") or defined("AUTOFILL_QXWZMC3") or defined("AUTOFILL_QXWZDZ3")) {
?>    
    <div class="footer">
      <div class="wrap_con">
        <h3>旗下网站</h3>
        <div class="footer_nav">
<?php
    }       
    if (defined("AUTOFILL_QXWZMC1") && defined("AUTOFILL_QXWZDZ1")) {
?>  
			<a href="<?php echo(AUTOFILL_QXWZDZ1); ?>" target="_blank"><?php echo(AUTOFILL_QXWZMC1); ?></a>
			|
<?php
    }                                                                     
    if (defined("AUTOFILL_QXWZMC2") && defined("AUTOFILL_QXWZDZ2")) {
?>            
			<a href="<?php echo(AUTOFILL_QXWZDZ2); ?>" target="_blank"><?php echo(AUTOFILL_QXWZMC2); ?></a>
			|
<?php
    }                                                                     
    if (defined("AUTOFILL_QXWZMC3") && defined("AUTOFILL_QXWZDZ3")) {
?>            
			<a class="hint-new" href="<?php echo(AUTOFILL_QXWZDZ3); ?>" target="_blank"><?php echo(AUTOFILL_QXWZMC3); ?></a>
		</div>
       
		<p><a href="http://www.miitbeian.gov.cn/" target="_blank">
          <?php if(defined("AUTOFILL_FOOTER_CODE")){ ?>
					<?php echo(stripslashes(AUTOFILL_FOOTER_CODE));?> </a></p>
		  <?php } ?>        
		<p><a  style="color: #c0392b;" >Copyright <?php printf( __( 'Copyright &copy; %s' ) , defined("AUTOFILL_FOOTER_YEAR") ? htmlspecialchars(stripslashes(AUTOFILL_FOOTER_YEAR)).'-'.date("Y") : date("Y") ); ?>  http:<?php echo(SITE_URL); ?> ®. All rights reserved. <?php echo(AUTOFILL_SEO); ?>版权或产权保护</a></p>
	</div>
    </div>
<?php
    }                                                                     
?>       
<div class="bottom_fix">
<!--返回顶部-->
<a href="javascript:;" class="go_top" id="go_top_btn">返回顶部</a>
</div>
   <?php
	if (defined("AUTOFILL_BAIDUTJ")) {
?>
<?php echo(AUTOFILL_BAIDUTJ); ?>
  <?php
	}
?> 
<script type="text/javascript" src="<?php echo(SITE_URL); ?>ziyuan/js/jquery-1.7.min.js" ></script>
<script type="text/javascript" src="<?php echo(SITE_URL); ?>ziyuan/js/common.js"></script>
<script>
        PostbirdImgGlass.init({
            domSelector:".img-container img",
            animation:true
        });
</script>
<script type="text/javascript" >
//global options
var STATIC_URL = '<?php echo(SITE_URL); ?>';
$.ajaxSetup({ cache:true });
ds.Dialog.defaults.iconBasePath = 'ziyuan/images/';

//Navigator autoFixed
$.getScript(STATIC_URL + 'ziyuan/js/jquery.autoFixed.js', function(){
	$('#header').autoFixed();
});

//返回顶部
jQuery(function($){
	var timer, view = $(window), btn = $('#go_top_btn');

	function scrollHandler(){
		clearTimeout(timer);
		timer = setTimeout(checkScroll, 160);
	}
	function checkScroll(){
		var top = view.scrollTop();
		btn[top > 100 ? 'removeClass' : 'addClass']('hide');
	}

	btn.bind('click', function(){
		btn.addClass('hide');
		ds.scrollTo(0);
	});
	view.bind('scroll', scrollHandler);
	scrollHandler();
});
</script>	

<script>
(function(){
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    }
    else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>
		
	</body>
</html>
